package com.xcf.controller.business.common;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xcf.controller.base.BaseController;
import com.xcf.entity.Page;
import com.xcf.service.business.common.companymanagement.CompanyManagementService;
import com.xcf.util.PageData;

@Controller
@RequestMapping(value = "/company")
public class CompanyManagementController extends BaseController {
	@Resource
	private CompanyManagementService companymanagement;
	String menuUrl = "company/managment"; // 菜单地址(权限用)

	@RequestMapping(value = "/managment")
	// 条件查询及列表查询
	public ModelAndView company(Page page) {
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		try {
			pd = this.getPageData();
			String COMPANY_NAME = pd.getString("COMPANY_NAME");
			if (null != COMPANY_NAME && !"".equals(COMPANY_NAME)) {
				pd.put("COMPANY_NAME", COMPANY_NAME.trim());
			}
			page.setPd(pd);
			List<PageData> list = companymanagement.seach(page);
			mv.setViewName("/business/common/companymanagement/company_management");
			mv.addObject("list", list);
			mv.addObject("pd", pd);
		} catch (Exception e) {

			e.printStackTrace();
		}

		return mv;

	}
	//点添加新增一条
		@RequestMapping(value="/addcompany")
		@ResponseBody
		public String addcost(){
			PageData pd = new PageData();
			    pd = this.getPageData();
				try {
					companymanagement.addcompany(pd);				
				} catch (Exception e) {				
					e.printStackTrace();
				}
				return null;

		}
		
		//修改页面
		@RequestMapping(value="edit")
		public ModelAndView companytedit(){
		ModelAndView mv = this.getModelAndView();
		  try {
			  PageData pd = new PageData();
			  pd = this.getPageData();
			  pd= companymanagement.seacById(pd);
			  mv.addObject("pd", pd);
			  mv.setViewName("/business/common/companymanagement/companymanagement_edit");
		} catch (Exception e) {
			e.printStackTrace();
		}
		  return mv;
		}
		
		//点击保存按钮
		@RequestMapping(value="saveU")
		@ResponseBody
		public String savaU(){
		
			PageData pd = new PageData();
			pd = this.getPageData();
			try {
				companymanagement.savaU(pd);
				
			} catch (Exception e) {
				
				e.printStackTrace();
			}
			return null;
		
			
		}
		//删除
		@RequestMapping(value="deleteU")
		@ResponseBody
		public String deleteU(){
			PageData pd = new PageData();
			pd = this.getPageData();
			try {
				companymanagement.delete(pd);
				
			} catch (Exception e) {
				
				e.printStackTrace();
			}
			return null;
				
		}
		
}

